package com.xiaoshuidi.cloud.module.report.controller.datamanage;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.report.controller.datamanage.vo.*;
import com.xiaoshuidi.cloud.module.report.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.report.service.datamanage.BusinessDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Slf4j
@Tag(name = "数据管理 - 业务数据")
@RestController
@RequestMapping(ApiConstants.DATA_MANAGE + "/business-data")
public class BusinessDataController {

    @Resource
    private BusinessDataService businessDataService;

    @PostMapping("/overview-of-house")
    @Operation(summary = "在租房源总览")
    public CommonResult<OverviewOfHouseRespVO> overviewOfHouse(@RequestBody OverviewOfHouseReqVO reqVO){
        return success(businessDataService.overviewOfHouse(reqVO.getApartmentIds(), reqVO.getCondition()));
    }

    @PostMapping("/rental-statistics")
    @Operation(summary = "在租房源出租率统计")
    public CommonResult<RentalStatisticsRespVO> rentalStatistics(@RequestBody @Valid RentalStatisticsReqVO reqVO){
        return success(businessDataService.rentalStatistics(reqVO.getApartmentIds(), reqVO.getStartDate(), reqVO.getEndDate()));
    }

    @PostMapping("/empty-room-change-trend")
    @Operation(summary = "空置房源变化趋势")
    public CommonResult<List<EmptyRoomChangeTrendRespVO>> emptyRoomChangeTrend(@RequestBody @Valid EmptyRoomChangeTrendReqVO reqVO){
        return success(businessDataService.emptyRoomChangeTrend(reqVO.getApartmentIds(), reqVO.getStartDate(), reqVO.getEndDate()));
    }

    @PostMapping("/signing-overview")
    @Operation(summary = "签约总览")
    public CommonResult<SigningOverviewRespVO> signingOverview(@RequestBody SigningOverviewReqVO reqVO){
        return success(businessDataService.signingOverview(reqVO.getApartmentIds()));
    }

    @PostMapping("/ranking-of-contracted-personnel")
    @Operation(summary = "签约人员排名")
    public CommonResult<List<RankingOfContractedRespVO>> rankingOfContractedPersonnel(@RequestBody @Valid RankingOfContractedReqVO reqVO){
        return success(businessDataService.rankingOfContractedPersonnel(reqVO.getApartmentIds(), reqVO.getRankingMode(), reqVO.getStartDate(), reqVO.getEndDate()));
    }

    @PostMapping("/ranking-of-contracted-apartment")
    @Operation(summary = "门店签约排名")
    public CommonResult<List<RankingOfContractedRespVO>> rankingOfContractedApartment(@RequestBody @Valid RankingOfContractedReqVO reqVO){
        return success(businessDataService.rankingOfContractedApartment(reqVO.getApartmentIds(), reqVO.getRankingMode(), reqVO.getStartDate(), reqVO.getEndDate()));
    }

    @PostMapping("/contract-expiration-num")
    @Operation(summary = "合同到期数")
    public CommonResult<List<ContractExpirationNumRespVO>> contractExpirationNum(@RequestBody @Valid ContractExpirationNumReqVO reqVO){
        return success(businessDataService.contractExpirationNum(reqVO.getApartmentIds()));
    }
}
